package com.yunda.nebula.gateway.config;

import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.yunda.nebula.gateway.listener.DataChangeListener;
import com.yunda.nebula.gateway.listener.nacos.NacosConfigRefresh;
import com.yunda.nebula.gateway.listener.nacos.NacosDataChangeListener;
import com.yunda.nebula.gateway.service.ITbGatewayAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfigAutoConfiguration {


    @Configuration
    @ConditionalOnProperty(name = "nebula.gateway.sync.type",havingValue = "nacos")
     class NacosConfigAutoConfiguration{

        @Bean
        public DataChangeListener nacosDataChangeListener(ITbGatewayAppService appService, NacosConfigProperties nacosConfigProperties){
            return new NacosDataChangeListener(appService,nacosConfigProperties);
        }

        @Bean
        @Autowired
        public NacosConfigRefresh nacosConfigRefresh(ITbGatewayAppService appService, NacosConfigProperties nacosConfigProperties){
            return new NacosConfigRefresh(appService,nacosConfigProperties);
        }




    }




}
